﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//
using Aop;
using Entitys;
using Entitys.SysClass;
using DbFrame;
using DbFrame.BaseClass;
using Toolkit;
using Toolkit.ValidateHelper;
using Logic.SysClass;
using System.Threading.Tasks;

namespace HzyAdmin.Areas.Admin.Controllers
{
    [AopActionFilter]
    public class LoginController : AdminBaseController
    {
        //
        // GET: /Admin/Login/
        AccountLogic _Logic = new AccountLogic();

        public LoginController()
        {
            this.IgnoreSessionCheck = true;
        }

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 验证
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> Check(string UserName, string UserPassword, string LoginCode)
        {
            var token = await _Logic.CheckedAsync(UserName, UserPassword, LoginCode);
            return this.Success(new
            {
                status = 1,
                jumpurl = AppConfig.HomePageUrl + "#!%u9996%u9875#!/Admin/Home/Main/",
                token = token
            });
        }

        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetYZM()
        {
            ValidateCodeHelper vch = new ValidateCodeHelper();
            string code = vch.GetRandomNumberString(4);
            Tools.SetCookie("loginCode", code, 2);
            return File(vch.CreateImage(code), "image/jpeg");
        }

        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        public ActionResult Out()
        {
            Tools.RemoveCookie("Authorization");
            //var cookie = Request.Cookies["Authorization"];
            //cookie.Expires = DateTime.Now.AddDays(-1);
            //cookie.Value = null;
            //Response.Cookies.Add(cookie);
            //Response.Cookies.Remove("Authorization");
            //Request.Cookies.Remove("Authorization");
            return RedirectToAction("Index");
        }


    }
}
